import 'package:dio/dio.dart';

class ParamsInterceptor extends Interceptor {
  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    var headers = options.headers;
    String? token = "token";
    if (token != null) {
      headers['token'] = token;
    }
    headers['project_token'] = '42AA73E97A2F49EF8EBB8FE20414072E';
    headers['uk'] = '59a0378351f30f4384c5ecf0985b5c52';
    headers['channel'] = 'cretin_open_api';
    headers['app'] = '1.0.0;1;13';
    headers['device'] = 'HUAWEI;CDY-AN00';
    super.onRequest(options, handler);
  }

  static Future<String> dioError(DioException error) async {
    switch (error.type) {
      case DioExceptionType.badCertificate:
        return '证书有误！';
      case DioExceptionType.badResponse:
        return '服务器异常，请稍后重试！';
      case DioExceptionType.cancel:
        return '请求已被取消，请重新请求';
      case DioExceptionType.connectionError:
        return '连接错误，请检查网络设置';
      case DioExceptionType.connectionTimeout:
        return '网络连接超时，请检查网络设置';
      case DioExceptionType.receiveTimeout:
        return '响应超时，请稍后重试！';
      case DioExceptionType.sendTimeout:
        return '发送请求超时，请检查网络设置';
      case DioExceptionType.unknown:
        return '网络异常！';
    }
  }
}
